package com.cy.pj.sys.controller;

import com.cy.pj.common.util.PageUtil;
import com.cy.pj.common.web.pojo.JsonResult;
import com.cy.pj.sys.pojo.CGBInformation;
import com.cy.pj.sys.service.CGBInformationService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.apache.shiro.subject.Subject;


@RestController
@RequestMapping("/information/")
public class CGBInformationController {
    @Autowired
    private CGBInformationService cgbInformationService;
//    @GetMapping("login/{username/{password}")
//    public JsonResult doLogin(@PathVariable String username,@PathVariable String password){
//        Subject subject= SecurityUtils.getSubject();
//        AuthenticationToken token=
//                new UsernamePasswordToken(username, password);
//        return new JsonResult("login ok");
//    }
    @GetMapping("{id}")
    public JsonResult doFindById(@PathVariable Integer id){
        return new JsonResult(cgbInformationService.selectById(id));
    }

    @PutMapping
    public JsonResult doUpdateNotice(@RequestBody CGBInformation information){
        cgbInformationService.updateUser(information);
        return new JsonResult("update ok");
    }
    @PostMapping
    public JsonResult doSaveNotice(@RequestBody CGBInformation information){
        cgbInformationService.insertUser(information);
        return new JsonResult("save ok");//json序列化(将对象转换为json格式字符串)
    }
//    @RequiresPermissions("CGB:information:view")
    @GetMapping
    public JsonResult doFindInformation(CGBInformation information){
        return new JsonResult(PageUtil.startPage()
        .doSelectPageInfo(()->{
            cgbInformationService.selectUsers(information);
        }));
    }
//    @PatchMapping("{id}/{valid}")
//    public JsonResult doValidById(@PathVariable Integer id,@PathVariable Integer valid){
//        cgbInformationService.validById(id, valid);
//        return new JsonResult("update ok");
//    }

}
